<?php
class Sistema_Login {

	/**
	 * logar
	 * 
	 * @abstract verifica o email e a senha do cara que quer se logar 
	 * 
	 * @param $usr_email
	 * @param $usr_senha
	 * 
	 * @return void
	 */
	public static function logar($usr_email, $usr_senha)
	{
		$sql = " 
		SELECT
			*
		FROM user
		WHERE
			usr_email = '".$usr_email."' AND
			usr_password = '".sha1($usr_senha)."'";

		$usuario = Sistema_Conecta::select($sql);

		if(sizeof($usuario))
		{
			$_SESSION['user']['usr_id']    = $usuario[0]['usr_id'];
			$_SESSION['user']['usr_name']  = $usuario[0]['usr_name'];
			$_SESSION['user']['usr_email'] = $usuario[0]['usr_email'];
			
			return true;
		} else {
			return false;
		}
	}

	public static function getNome()
	{
		return $_SESSION['user']['usr_name'];
	}

	public static function getEmail()
	{
		return $_SESSION['user']['usr_email'];	
	}
	
	public static function getId()
	{
		return $_SESSION['user']['usr_id'];	
	}	
	
	/**
	 * logout
	 * 
	 * @abstract  
	 * 
	 * @return void
	 */
	public static function logout()
	{
		unset($_SESSION['user']);
		header("Location:index.php?m=Ffront&c=index");			
	}
}
?>